package extraction;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class ConfigurationFileReader {
	public ConfigurationFileReader(String confPath){
		FileInputStream ips = null;
		try {
			ips = new FileInputStream(confPath);
		} catch (FileNotFoundException e) {
			System.err.println("Fichier de configuration introuvable");
//			e.printStackTrace();
		}
		InputStreamReader ipsr = new InputStreamReader(ips);
		BufferedReader br = new BufferedReader(ipsr);
		String line;
		StringTokenizer st;
		try {
			while ((line = br.readLine())!= null){
				if(!line.matches("#.*")){
					st = new StringTokenizer(line, "=");
					name.add(st.nextToken());
					value.add(st.nextToken());
				}
			}
			br.close();
		} catch (IOException e) {
			System.err.println("Impossible de lire le fichier de configuration");
//			e.printStackTrace();
		}
	}
	
	public String getValue(String name){
		return value.get(this.name.indexOf(name));
	}
	
	private ArrayList<String> name = new ArrayList<String>();
	private ArrayList<String> value = new ArrayList<String>();
}
